package tjx.Listener;

import javax.servlet.*;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.*;

//@WebListener()
public class RequestListener implements ServletRequestListener, ServletRequestAttributeListener {
    public void attributeAdded(ServletRequestAttributeEvent servletRequestAttributeEvent) {
        ServletContext application=servletRequestAttributeEvent.getServletContext();
        String name=servletRequestAttributeEvent.getName();
        Object value=servletRequestAttributeEvent.getValue();
        System.out.println(application+"范围内添加了名为"+name+",值为"+value+"的属性！");
    }

    public void attributeRemoved(ServletRequestAttributeEvent servletRequestAttributeEvent) {
        ServletContext application=servletRequestAttributeEvent.getServletContext();
        String name=servletRequestAttributeEvent.getName();
        Object value=servletRequestAttributeEvent.getValue();
        System.out.println(application+"范围内名为"+name+",值为"+value+"的属性被删除了！");
    }

    public void attributeReplaced(ServletRequestAttributeEvent servletRequestAttributeEvent) {
        ServletContext application=servletRequestAttributeEvent.getServletContext();
        String name=servletRequestAttributeEvent.getName();
        Object value=servletRequestAttributeEvent.getValue();
        System.out.println(application+"范围内名为"+name+",值为"+value+"的属性被替换了！");
    }

    public void requestDestroyed(ServletRequestEvent servletRequestEvent) {
        HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();
        System.out.println("----发向"+request.getRequestURI()+"请求被销毁----");
    }

    public void requestInitialized(ServletRequestEvent servletRequestEvent) {
        HttpServletRequest request=(HttpServletRequest)servletRequestEvent.getServletRequest();
        System.out.println("----发向"+request.getRequestURI()+"请求被初始化----");
    }
}
